package com.pacs.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

public class AccessControlInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		//设置跨域访问 
		Controller controller = inv.getController();
		String origin = controller.getRequest().getHeader("Origin");
		controller.getResponse().setHeader("Access-Control-Allow-Origin", origin);
		controller.getResponse().setHeader("Access-Control-Allow-Credentials", Boolean.TRUE.toString());
		controller.getResponse().setHeader("Access-Control-Allow-Headers", "x-requested-with,content-type");
		
		if ("OPTIONS".equals(inv.getController().getRequest().getMethod())){
			inv.getController().renderText("");;
		}
		
		inv.invoke();
	}

}
